<?php
namespace App\Controller;
use Think\Controller;

class BillController extends Controller{
	function update(){
		$bill = M('_Bill');
		$data['createtime'] = I('post.createtime');
		$data['type'] = I('post.type');
		$data['specific'] = I('post.specific');
		$data['price'] = I('post.price');
		$data['no'] = I('post.no');
		$data['total'] = I('post.total');
		$data['remark'] = I('post.remark');
		$data['userid'] = I('post.userid');

		$map['userid'] = I('post.userid');
		$map['createtime'] = I('post.createtime');

		$res = $bill->where($map)->find();
		if ($res != null) {
			$bill->where($map)->save($data);
			$r['code'] = 4;
			$r['msg'] = '更新成功';
			$this->ajaxReturn($r,'JSON');
		} else{
			$bill->add($data);
			$r['code'] = 4;
			$r['msg'] = '添加';
			$this->ajaxReturn($r,'JSON');
		}
	}

	function get($userid){
		$bill = M('_Bill');
		$map['userid'] = $userid;
		$res['bills'] = $bill->where($map)->select();
		if ($res['bills'] != null) {
			$res['code'] = 2;
			$res['msg'] = '获取账单数据';
			$this->ajaxReturn($res, 'JSON');
		} else{
			$res['code'] = 3;
			$res['msg'] = '无账单数据';
			$this->ajaxReturn($res, 'JSON');
		}
	}
}